<script src="<?php echo APP_DOMAIN . '/public/ckeditor/ckeditor.js'; ?>" type="text/javascript"></script>
<script src="<?php echo APP_DOMAIN . '/application/layouts/' . $this->page->templates . '/js/datepicker/mootools-core.js'; ?>" type="text/javascript"></script>
<script src="<?php echo APP_DOMAIN . '/application/layouts/' . $this->page->templates . '/js/datepicker/mootools-more.js'; ?>" type="text/javascript"></script>
<script src="<?php echo APP_DOMAIN . '/application/layouts/' . $this->page->templates . '/js/datepicker/Picker.js'; ?>" type="text/javascript"></script>
<script src="<?php echo APP_DOMAIN . '/application/layouts/' . $this->page->templates . '/js/datepicker/Picker.Attach.js'; ?>" type="text/javascript"></script>
<script src="<?php echo APP_DOMAIN . '/application/layouts/' . $this->page->templates . '/js/datepicker/Picker.Date.js'; ?>" type="text/javascript"></script>  
<link href="<?php echo APP_DOMAIN . '/application/layouts/' . $this->page->templates . '/css/datepicker_vista.css'; ?>" rel="stylesheet" type="text/css" />

<div class="form_view">
    <p style="color: #800000;font-weight: bold;"><?php echo $this->message; ?></p>
    <form method="post" action="<?php echo APP_DOMAIN; ?>/manage/join" name="join">
       
		<table class="dkthamgia">
		<tr>
            <td width="130"><span class="text_style">Họ tên *:</span></td>
            <td><input class="imputstyle2" type="text" id="name" name="name" value="<?php echo $this->info->ten_thi_sinh; ?>"/></td>
        </tr>
        <tr>
            <td><span class="text_style">Ngày sinh :</span></td>
            <?php
            if ($this->info->ngay_sinh > 0) {
                $date = date('m/d/Y', $this->info->ngay_sinh);
            } else {
                $date = '';
            }
            ?>
            <td><input class="imputstyle2" type="text" id="birthday" name="birthday" value="<?php echo $date; ?>"/><span class="text_style">(mm/dd/yyyy)</span></td>
        </tr>        
        <tr>
            <td><span class="text_style">Giới tính :</span></td>
			<td>
            <select class="selectstyle2" name="gender" id="gender">
                <option value="0">Nữ</option>
                <option value="1">Nam</option>
            </select> 
			</td>
        </tr>
        <tr>
            <td><span class="text_style">CMND :</span></td>
            <td><input class="imputstyle2" type="text" name="cmnd" value="<?php echo $this->info->cmnd; ?>"/></td>
        </tr>
        <tr>
            <td><span class="text_style">Email *:</span></td>
            <td><input class="imputstyle2" type="text" id ="email" name="email" value="<?php echo $this->info->email; ?>"/></td>
        </tr>
        <tr>
            <td><span class="text_style">Số điện thoại :</span></td>
            <td><input class="imputstyle2" type="text" name="so_dien_thoai" value="<?php echo $this->info->so_dien_thoai; ?>"/></td>
        </tr>
	</table>
	
	
        <div class="f_row">
            <span class="text_style">Giới thiệu : </span> 
            <div class="f_content">
                <textarea class="styletarea" name="gioi_thieu" id="gioi_thieu" cols="75" rows="10"><?php echo $this->info->gioi_thieu; ?></textarea>
                <script type="text/javascript" language="javascript">
                    CKEDITOR.replace('gioi_thieu', {
                        toolbar: 'Content',
                        width: 580
                    });
                </script>
            </div> 
        </div>
        <div class="clear"></div>
        <div class="f_row">
            <span class="text_style">Mô tả : </span>  
            <div class="f_content">
                <textarea class="styletarea" name="mo_ta_bai_thi" id="mo_ta_bai_thi" cols="75" rows="10"><?php echo $this->info->mo_ta_bai_thi; ?></textarea>
                <script type="text/javascript" language="javascript">
                    CKEDITOR.replace('mo_ta_bai_thi', {
                        toolbar: 'Content',
                        width: 580
                    });
                </script>
            </div> 
        </div>        
        <p>            
            <textarea id="hinh_du_thi" name="hinh_du_thi" style="display: none;"><?php echo $this->hinh_du_thi; ?></textarea>
        </p>
    </form>
    <form id='file_upload_form' method='post' enctype='multipart/form-data' action='<?php echo APP_DOMAIN . '/manage/upload'; ?>'>
        <p>
            <span class="text_style">Hình dự thi *: </span>  
            <input name='data_src' id='data_src' size='27' type='file' />
            <span><a class="text_style" href="javascript:void(0);" onclick="processUpload();">Đăng ảnh</a></span>            
            <span id="msg"></span>
            <input type='hidden' name='action'  value='10' />
            <input type='hidden' name='callback'  value='uploadComplete' />
            <iframe id='upload_target' name='upload_target' src='' style='width:0;height:0;border:0px solid #fff;'></iframe>
        </p> 
    </form>
    <form>
        <p id="image_content">
            <span></span>  
        </p>
    </form>
    <p class="btluu">
        <a class="text_style" href="javascript:void(0);" onclick="postInfo();">Lưu</a>
    </p>
</div>

<script>   
    var count =0;
    //Change these values to style your modal popup
    var align = 'center';									//Valid values; left, right, center
    var ptop = 400; 											//Use an integer (in pixels)
    var width = 0; 										//Use an integer (in pixels)
    var padding = 10;										//Use an integer (in pixels)
    var backgroundColor = '#FFFFFF'; 						//Use any hex code
    var source = 'asdasda'; 								//Refer to any page on your server, external pages are not valid e.g. http://www.google.co.uk
    var borderColor = '#333333'; 							//Use any hex code
    var borderWeight = 4; 									//Use an integer (in pixels)
    var borderRadius = 5; 									//Use an integer (in pixels)
    var fadeOutTime = 300; 									//Use any integer, 0 = no fade
    var disableColor = '#666666'; 							//Use any hex code
    var disableOpacity = 40; 								//Valid range 0-100
    var loadingImage = 'lib/release-0.0.1/loading.gif';		//Use relative path from this page

    source = '<table style="text-align: center; width: 400px;"><tr><td>';
    source +="[content]";
    source +="</td></tr></table>";
        
    function processUpload(){
        if(count<<?php echo MAX_IMAGE; ?>){
            $("#msg").html("Đang xử lý ...");
            document.getElementById('file_upload_form').target = 'upload_target'; //'upload_target' is the name of the iframe                              
            document.getElementById('file_upload_form').submit();
        }else{
            $("#msg").html("Số hình vượt quá số lượng quy định");
        }        
        return false;
    }
    
    function uploadComplete(data) {        
        if(data.errorCode >=0){   
            var html = $("#hinh_du_thi").val();
            if($("#hinh_du_thi").val()!=''){
                html +=';';                
            }
            html+=data.data;
            var link = '<?php echo APP_DOMAIN; ?>' + '/public/images/'+data.data;
            var img = "<img src='"+link+"' height='100px' style='margin: 2px; border: 1px solid;' />"
            $('#image_content').append(img);
            $("#hinh_du_thi").val(html);
            $("#data_src").val('');
            $("#msg").html('');
            ++count;
        }else{
            $("#msg").html(data.message);
        }              
    }
    
    function postInfo() {
        var message = '';
        var name = document.getElementById('name');
        var email = document.getElementById('email');
        var image = document.getElementById('hinh_du_thi');
        
        if(message == '' && name.value ==''){
            message = 'Bạn chưa nhập tên';
        } 
        
        if(message == '' && email.value ==''){
            message = 'Bạn chưa nhập email';
        }
        
        if(message == '' && image.value ==''){
            message = 'Bạn chưa có hình dự thi nào';
        }        
    
        if(message != ''){
            message = source.replace('[content]',message);
            modalPopup(align, ptop, width, padding, disableColor, disableOpacity, backgroundColor, borderColor, borderWeight, borderRadius, fadeOutTime, message, loadingImage);
        }else{
            document.join.submit();
        }
        return false;        
    }
    
    
    $(function () {	
        new Picker.Date('birthday', {			
            pickerClass: 'datepicker_vista'			
        });
		
        common.selectOptionByValue('gender', '<?php echo $this->info->gioi_tinh; ?>');    
    });
    
    
</script>
